/*
 * Copyright (c) 2012, 2021, daojian.co and/or its affiliates. All rights reserved.
 *
 */

package co.bugu.code.analysis.application.converter;

import co.bugu.code.analysis.application.dto.CommitDto;
import co.bugu.code.analysis.infra.entity.Commit;
import org.springframework.beans.BeanUtils;

/**
 * 数据转换类
 *
 * @author happy-coder
 * @version 1.0.0
 * @createdAt 2022-06-11 11:21:37
 * @updatedAt 2022-06-11 11:21:37
 */
public class CommitConverter {
    public static CommitDto entityToDto(Commit entity) {
        if (null == entity) {
            return null;
        }
        CommitDto res = new CommitDto();
        BeanUtils.copyProperties(entity, res);
        return res;

    }

    //    实现从gitlab4j的Commit对象转换为infra的Commit对象
    public static co.bugu.code.analysis.infra.entity.Commit convert(Long projectId, Long branchId, String branchName, org.gitlab4j.api.models.Commit commit) {
        co.bugu.code.analysis.infra.entity.Commit infraCommit = new co.bugu.code.analysis.infra.entity.Commit();
        BeanUtils.copyProperties(commit, infraCommit);
        infraCommit.setProjectId(projectId);
        infraCommit.setCommitId(commit.getId());
        infraCommit.setTitle(commit.getTitle());
        infraCommit.setMessage(commit.getMessage());
        infraCommit.setBranchName(branchName);
        infraCommit.setAdditions(commit.getStats().getAdditions());
        infraCommit.setDeletions(commit.getStats().getDeletions());
        infraCommit.setTotal(commit.getStats().getTotal());
        infraCommit.setBranchId(branchId);
        return infraCommit;
    }
}
